package com.wonderland.sail.mybatis.parser.impl;

import com.wonderland.sail.mybatis.model.Page;
import com.wonderland.sail.mybatis.parser.SqlParser;

/**
 * Created by gaoxinyu on 2015-05-20.
 */
public class OracleParser extends AbstractSqlParser implements SqlParser {

    @Override
    public String getPageSql(String sql, Page page) {
        return "select * from (select tmp_tb.*,ROWNUM row_id from (" + sql + getSortSql(page) + ") tmp_tb where ROWNUM<="
                + (page.getCurrentResult() + page.getPageSize()) + ") where row_id>" + page.getCurrentResult();
    }

    void getZhSortField(StringBuilder sortSql, String sortField) {
        sortSql.append("NLSSORT(")
                .append(sortField.substring(0, sortField.lastIndexOf("IsZh")))
                .append(",'NLS_SORT = SCHINESE_PINYIN_M')");
    }
}
